/*
 * @Author: szx
 * @Date: 2022-03-08 15:59:50
 * @LastEditTime: 2022-03-08 16:07:03
 * @Description:
 * @FilePath: \leetcode\500-599\538\538_2.js
 */
/**
 * @param {TreeNode} root
 * @return {TreeNode}
 */
var convertBST = function (root) {
    let prev = 0;
    const ReverseInOrde = (root) => {
        if (!root) return;
        ReverseInOrde(root.right);
        root.val += prev;
        prev = root.val;
        ReverseInOrde(root.left);
    };
    return ReverseInOrde(root);
};
